const { mysql } = require('../qcloud')

module.exports = async (ctx) => {
	const { openid } = ctx.request.body

	try {
		const res = await mysql('records')
									.where('openid',openid)
									.orderBy('id','desc').first()
		if (res) {
			var add = res.add
			await mysql('records')
				.where('id',res.id).del()
		} else {
			var add = 0
		}

		ctx.state.data = {
			code: 0,
			add: add,
			msg: 'success'
		} 
		console.log('执行成功')
	} catch (err) {
		console.log('执行错误:', err)
		ctx.state = {
			code: -1,
			data: {
				msg: '撤销失败' + e.sqlMessage
			}
		}
	}
}